package config;

import util.GetPath;
import util.ReadConfig;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;

/**
 * UserRank: tum0r
 * Package Name: config
 * Time: 2019-01-15 Tuesday 20:02:29
 */
public class ApplicationConfig {

    private static LinkedList<String> cDangerCode = null;
    private static LinkedList<String> javaDangerCode = null;
    private static LinkedList<String> pythonDangerCode = null;

    public static LinkedList<String> getDangerCode(String language) {
        if (cDangerCode == null) {
            cDangerCode = new LinkedList<>();
            ReadConfig readConfig = new ReadConfig();
            LinkedHashMap<String, String> dangerCodeMap = readConfig.readConfig("danger.json");
            String[] dangerContent;
            int i;
            dangerContent = dangerCodeMap.get("C/CPP").toLowerCase().split(":");
            for (i = dangerContent.length - 1; i >= 0; i--) {
                cDangerCode.add(dangerContent[i]);
            }
        }
        if (javaDangerCode == null) {
            javaDangerCode = new LinkedList<>();
            ReadConfig readConfig = new ReadConfig();
            LinkedHashMap<String, String> dangerCodeMap = readConfig.readConfig("danger.json");
            String[] dangerContent;
            int i;
            dangerContent = dangerCodeMap.get("Java").toLowerCase().split(":");
            for (i = dangerContent.length - 1; i >= 0; i--) {
                javaDangerCode.add(dangerContent[i]);
            }
        }
        if (pythonDangerCode == null) {
            pythonDangerCode = new LinkedList<>();
            ReadConfig readConfig = new ReadConfig();
            LinkedHashMap<String, String> dangerCodeMap = readConfig.readConfig("danger.json");
            String[] dangerContent;
            int i;
            dangerContent = dangerCodeMap.get("Python").toLowerCase().split(":");
            for (i = dangerContent.length - 1; i >= 0; i--) {
                pythonDangerCode.add(dangerContent[i]);
            }
        }
        if (language.equals("Java")) {
            return javaDangerCode;
        } else if (language.equals("C/CPP")) {
            return cDangerCode;
        } else {
            return pythonDangerCode;
        }
    }

    public static String getPath() {
        return new GetPath().getPath();
    }

    public static LinkedHashMap<String, String> readConfig(String fileName) {
        return new ReadConfig().readConfig(fileName);
    }

    public static LinkedHashMap<String, String> utf8Code() {
        LinkedHashMap<String, String> result = new LinkedHashMap<>();
        result.put("<", "&#60;");
        result.put(">", "&#62;");
        result.put("\"", "&#34;");
        result.put("'", "&#39;");
        return result;
    }

    public static LinkedHashMap<String, String> utf8CodeSpecial() {
        LinkedHashMap<String, String> result = new LinkedHashMap<>();
        result.put("&", "&#38;");
        return result;
    }

    public static LinkedHashMap<String, String> utf8CodeSpace() {
        LinkedHashMap<String, String> result = new LinkedHashMap<>();
        result.put(" ", "&nbsp;");
        return result;
    }

    public static String getBloodsAudio(String bloodName) {
        ReadConfig readConfig = new ReadConfig();
        LinkedHashMap<String, String> bloodConfig = readConfig.readConfig("audio.json");
        return bloodConfig.getOrDefault(bloodName, "");
    }
}
